function changeCode() {
    //http访问后台时，如果地址一样，则直接从缓存里面取数据
    $(".name-img").attr("src", "/code?aa=" + Math.random());
}

function login() {
    let data = {
        username: $("#username").val(),
        password: $("#password").val(),
        code: $("#code").val()
    };
    $.ajax({
        url: '/login',
        data: data,
        type: 'post',
        dataType: 'json',
        success: function (data) {
            if (data.result == 'success') {
                sessionStorage.setItem("username", $("#username").val());
                window.open("/admin/index.html");
            }
            if (data.result == 'error-code') {
                alert("验证码错误，请重新输入");
            }
            if (data.result == 'error') {
                alert("用户名或者密码错误，请重新输入");
            }
        }
    });
}